/*
 * A simple ToDo Manager
 *
 * Copyright (c) 2011 Nosheen Zaza, Manuel Rebollo, Seyedsaeid Mahpeikar and
 * Wo Ke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package todomanager.ui.tableview;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import todomanager.model.Task;
import todomanager.ui.ActionControl;


/**
 * A model to a table which holds a list of tasks.
 * 
 * @author
 * Nosheen Zaza
 */
public class TaskTableModel extends AbstractTableModel {

    protected List<Task> tasks;

    /**
     * Creates an instance with the given task list.
     * @param tasks a list of tasks.
     */
    public TaskTableModel(List tasks) {
        this.tasks = tasks;
    }

    /**
     * Returns the class of a column (all column are of {@code Task} class) 
     * @param columnIndex
     * @return Task.class
     */
    @Override
    public Class getColumnClass(int columnIndex) {        
            return Task.class;
    }

    /**
     * Returns column count
     * @return 3
     */
    public int getColumnCount() {
        return 3;
    }

    /**
     * Returns a column name.
     * @param columnIndex
     * @return column name
     */
    @Override
    public String getColumnName(int columnIndex) {
        if (columnIndex == 0) {
            return ActionControl.getInstance(
                    ).getStringsBundle().getString("edit.hintMessage");
        } else if (columnIndex == 1) {
            return ActionControl.getInstance(
                    ).getStringsBundle().getString("categoryLabel");
        } else {
            return ActionControl.getInstance(
                    ).getStringsBundle().getString("priorityLabel");
        }
    }

    /**
     * Returns row count.
     * @return row count
     */
    public int getRowCount() {
        return (tasks == null) ? 0 : tasks.size();
    }

    /**
     * Returns a value at the specifies row & column indices.
     * @param rowIndex
     * @param columnIndex
     * @return a task at [row, column]
     */
    public Object getValueAt(int rowIndex, int columnIndex) {
         return tasks.get(rowIndex);
    }

    /**
     * Returns whether a cell is editable.
     * @param columnIndex
     * @param rowIndex
     * @return true (a cell in this model is always editable)
     */
    @Override
    public boolean isCellEditable(int columnIndex, int rowIndex) {
        return true;
    }
}
